package statemode.context;

import observermode.observer.Zh0202Observer;
import statemode.state.Zh0202Level;
import statemode.state.Zh0202OrdinaryMember;

/**
 * @author: zh
 * @date: 2021/12/17 15:48
 * @version: 1.0
 */
public class Zh0202User extends Zh0202Observer {
    private String userName;
    private double paidMoney;
    private Zh0202Level userLevel;

    public Zh0202User(String userName) {
        this.userName = userName;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public double getPaidMoney() {
        return paidMoney;
    }

    public void setPaidMoney(double paidMoney) {
        this.paidMoney = paidMoney;
    }

    public Zh0202Level getUserLevel() {
        return userLevel;
    }

    public void setUserLevel(Zh0202Level userLevel) {
        this.userLevel = userLevel;
    }

    @Override
    public void response() {
        System.out.println("收到活动通知了！非常感谢！");
    }

    public void changeCredit(){
        if (userLevel.getClass() == Zh0202OrdinaryMember.class){
            System.out.println("很遗憾！您还不具有兑换的功能，请升级后再来尝试哦~");
        }else {
            userLevel.changeCredit();
        }
    }

    public void buyBook(){
        paidMoney = 100;
        System.out.println("你购买的图书售价为100元");
        System.out.println("您需要付款"+userLevel.calcRealAmount()+"元");
        userLevel.setScore(userLevel.getScore()+40);
        System.out.println("您的积分增加了40");
        userLevel.checkLevel();
        System.out.println("您的积分总额为"+userLevel.getScore());
    }
}
